package com.hd.crdao.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hd.crdao.R;
import com.hd.crdao.bean.LoanCarBillsBean;
import com.hd.crdao.utils.StringUtils;
import com.hd.crdao.utils.UIUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author Programming
 * @date 2017/10/18 0018
 */

public class LoanCarBillRVAdapter extends RecyclerView.Adapter {


    private List<LoanCarBillsBean.ListVehicleTblBean> mListVehicleTblBean;
    private OnItemClickListener mOnItemClickListener;

    public LoanCarBillRVAdapter( List<LoanCarBillsBean.ListVehicleTblBean> listVehicleTblBean) {

        this.mListVehicleTblBean = listVehicleTblBean;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(UIUtils.getContext()).inflate(R.layout.loancarbill_item, parent, false);
        return new ViewHolder(view);

    }

    @Override
    public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
        ViewHolder viewHolder = (ViewHolder) holder;
        final LoanCarBillsBean.ListVehicleTblBean listVehicleTblBean = mListVehicleTblBean.get(position);
        viewHolder.mFkDate.setText(listVehicleTblBean.getVehCredit().getFkDate());
        viewHolder.mVeBrand.setText(listVehicleTblBean.getVeBrand());
        viewHolder.mInterestDays.setText(listVehicleTblBean.getInterestDays());
        viewHolder.mInterestMoney.setText(StringUtils.doubleToString(listVehicleTblBean.getInterestMoney()));
        viewHolder.mVcCredit.setText(StringUtils.doubleToString(listVehicleTblBean.getVehCredit().getVcCredit()));
        viewHolder.mVcRate.setText(String.valueOf(listVehicleTblBean.getVehCredit().getVcRate())+"%");

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(mOnItemClickListener!=null){
                    mOnItemClickListener.onItemClick(v,holder.getAdapterPosition());
                }

            }
        });
    }

    @Override
    public int getItemCount() {
        if (mListVehicleTblBean != null) {
            return mListVehicleTblBean.size();
        }
        return 0;
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.item_loancar_head)
        ImageView mItemLoancarHead;
        @BindView(R.id.veBrand)
        TextView mVeBrand;
        @BindView(R.id.interestMoney)
        TextView mInterestMoney;
        @BindView(R.id.vcCredit)
        TextView mVcCredit;
        @BindView(R.id.vcRate)
        TextView mVcRate;
        @BindView(R.id.childset_layout)
        LinearLayout mChildsetLayout;
        @BindView(R.id.interestDays)
        TextView mInterestDays;
        @BindView(R.id.fkDate)
        TextView mFkDate;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }

    public interface OnItemClickListener{
        void onItemClick(View v,int position);
    }

    public void setOnItemClickListener(OnItemClickListener mOnItemClickListener){
        if(mOnItemClickListener!=null){
          this.mOnItemClickListener=  mOnItemClickListener;
        }
    }

}
